<template>
  <div class="addStaion-dialog">
    <div class="title">编辑</div>
    <dl>
      <dt>
        <input type="text" :value="this.$store.state.editValue" ref="input" />
      </dt>
      <dd style="text-align:center;">
        <span class="button-item" @click="cancelEvent">取消</span>
        <span class="button-item" @click="saveHandler">确认</span>
      </dd>
    </dl>
  </div>
</template>

<script>
export default {
  data() {
    return {}
  },
  mounted() {
    this.$refs.input.focus()
    if (this.$store.state.editKey == 'parav') {
      this.$refs.input.value = this.$store.state.table3Data[
        this.$store.state.editValueIndex
      ][this.$store.state.editKey]
    } else {
      this.$refs.input.value = this.$store.state.table2Data[
        this.$store.state.editValueIndex
      ][this.$store.state.editKey]
    }
  },
  methods: {
    //点击取消按钮
    cancelEvent() {
      this.$store.state.showEditDialog = false
    },
    //点击确定按钮
    saveHandler() {
      if (this.$store.state.editKey == 'parav') {
        this.$store.state.table3Data.map((item, index) => {
          if (item.index == this.$store.state.editValueIndex) {
            item.parav = this.$refs.input.value
          }
        })
      } else {
        this.$store.state.table2Data.map((item, index) => {
          if (index == this.$store.state.editValueIndex) {
            item[this.$store.state.editKey] = this.$refs.input.value
          }
        })
      }

      this.$store.state.showEditDialog = false
    },
  },
}
</script>

<style lang="less"></style>
